package com.qianclass.talklive.app.utils;

import com.qianclass.talklive.app.bean.MemberItemInfo;
import com.qianclass.talklive.app.bean.SortMemberBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Author:  Administrator
 * Date:    2017/3/27     15:01
 * TODO:    
 */

public class SortUtils {
    public static List<SortMemberBean> filledData(CharacterParser characterParser,
                                                  List<MemberItemInfo> memberItemInfos){
        List<SortMemberBean> mSortList = new ArrayList<SortMemberBean>();

        for(int i=0; i<memberItemInfos.size(); i++){
            SortMemberBean sortModel = new SortMemberBean();
            sortModel.setUsername(memberItemInfos.get(i).getUsername());
            sortModel.setAccount(memberItemInfos.get(i).getAccount());
            sortModel.setLikenum(memberItemInfos.get(i).getLikenum());
            sortModel.setType(memberItemInfos.get(i).getType());
            sortModel.setUserid(memberItemInfos.get(i).getUserid());
            //汉字转换成拼音
            String pinyin     = characterParser.getSelling(memberItemInfos.get(i).getUsername());
            String sortString = "";
            if (!pinyin.equals("")) {
                sortString = pinyin.substring(0, 1).toUpperCase();
            }

            // 正则表达式，判断首字母是否是英文字母
            if(sortString.matches("[A-Z]")){
                sortModel.setSortLetters(sortString.toUpperCase());
            }else{
                sortModel.setSortLetters("#");
            }

            mSortList.add(sortModel);
        }
        return mSortList;

    }
}
